<?php 
$user=$session->read('User');
$companyid=$session->read("companyid");
$isflag=$action->checkPermissions($user,$companyid);
?>
<div class="right_side_operate_area">
	<div class="right_side_title left">
    	<h2>
		<?php 
		$companyname=$session->read("companyname");
		echo $html->link($companyname,"/companys/showinfosummary/".$companyid);
		?>
    	</h2>
    	<div class='clear'></div>
    </div>
    <div class="right item_add_btn">
		<?php 
			if($form->value('CompTechnology.id')){
			$str_title=__("Edit",true);
			}else{
			$str_title=__("Add",true);
			}
    		echo $html->link(__("Cancel",true).$str_title,"/companys/technology/");
    	?>
	</div>
    <div class="clear"></div>
</div>

<div class="right_side_scollbar">
	<div class="detail_info_panel">
		<?php
		echo $form->create('Company', array('url' => "/companys/edittechnology",'id'=>'teconologyform','enctype'=>'multipart/form-data','onsubmit'=>"return checksave()"));
		?>
		<div class="details_item_line">
			<div class="details_item">
	   			 <div class="form_left_title left"><font style="color:red">*</font><?php echo "项目名称" ;?>：</div>
	    		 <div class="form_right_e_input left"><?php echo $form->text('CompTechnology.tname');?></div>
	   		 	 <div id='technologynamemessage' style='display:none;' class="error_message">请填写立项名</div>
			</div>
		</div>
		<?php 
		foreach($alltechnologies as $key=>$technology){
 			$pid[$key] = $technology;
 		}
		?>		
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"><font style="color:red">*</font>立项类型：</div>
			    <div class="form_right_e_input left">
			   <?php echo $form->select('CompTechnology.type_id',$types, null, null,null);?>
			    </div>
			    <div id='technologytypemessage' style='display:none;' class="error_message">请选择类型</div>
			</div>		
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"><font style="color:red">*</font>主管部门：</div>
			    <div class="form_right_e_input left">
			    <?php $selecttalstacktype=$form->value("CompTechnology.department"); ?>
			    <?php echo $form->select('CompTechnology.department',$talstacktype, $selecttalstacktype, null,null);?>			    
			    </div>
			    <div id='departmentemessage' style='display:none;' class="error_message">请选择主管部门</div>
			</div>
		</div>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
			    <div class="form_left_title left">申报状态：</div>
			   <div class="form_right_e_input left">
			    	 <?php echo $form->select('CompTechnology.declarate_status',$statues,null,null,null);?>
			    </div>
			    <div id='declaratestatusmemessage' style='display:none;' class="error_message">请选择状态</div>
			</div>
		</div>
		<?php 
		//立项状态
		$state = classregistry::init('Constant')->Technologystatus;
		foreach($alltechnologies as $key=>$technology){
 			$pid[$key] = $technology;
 		}
 		?>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
				<div class="form_left_title left">立项状态：</div>
				<div class="form_right_e_input left">				
			    <?php 
			    $select=$form->value('CompTechnology.state');
			    if(empty($id)){
	    			$select="0";
	   			}
			    echo $form->select('CompTechnology.state',$state,$select, null,null);?>
			    </div>
			    <div id='technologystatemessage' style='display:none;' class="error_message">请选择所处状态</div>				
			</div>
		</div>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
				<div class="form_left_title left">申请时间：</div>
		    	<div class="form_right_e_input left">
		    		<div class="form_right_e_input form_date_picker left">
		    			<?php echo $form->text('CompTechnology.apply_time',array("style"=>"width:130px","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
			    	</div>
		    	</div>
			</div>
	    	<div id="AcceptTime" class="details_item" style="display:none">
		    	<div class="form_left_title left">受理时间：</div>
		    	<div class="form_right_e_input left">
		    		<div class="form_right_e_input form_date_picker left">
			    		<?php echo $form->text('CompTechnology.accept_time',array("style"=>"width:130px;","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
			    	</div>
		    	</div>   
	    	</div>
	    	<div id="AuthorizeTime" class="details_item" style="display:none">
		    	<div class="form_left_title left">授权时间：</div>
		    	<div class="form_right_e_input left">
		    		<div class="form_right_e_input form_date_picker left">
			    		<?php echo $form->text('CompTechnology.authorize_time',array("style"=>"width:130px;","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
			    	</div>
		    	</div>
	    	</div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
	    		<div class="form_left_title left"><?php echo "立项介绍" ;?>：</div>
	    		<div class="form_right_e_input left"><?php echo $form->textarea('CompTechnology.content',array('class' => 'form_textarea'));?></div>
			</div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"><?php echo "附件";?>：</div>
			    <div class="form_right_input left">
			    <?php if($attachments){?>
                	<div class="file_category_list">
		        		<div id="filelist0" class="file_lists">
		        			<ul class="file_attach">
			                	<?php
			                	$dan="'";
			                	foreach($attachments as $attachment) {
										echo "<li>";
										echo "<span>".$html->link($attachment["file_name"],'/projects/download/'.$attachment["id"],null)."</span>";
										echo "<span class='source_upload_date'>".date("Y-m-d",strtotime($attachment["created"]))."</span>";
										if($action->checkPermissions($user,$companyid)){
											echo '<span class="source_upload_delete"><a title="删除" onclick="delfile(this,'.$dan.$attachment["id"].$dan.',0)" href="javascript:void(0)"></a></span>';
										}
										echo "</li>";
								}
			                	?>
			                </ul>
		                </div>
		            </div>
		        <?php }?>
			    <div id="add1" class="left text_box"> 
					<div class="file_add_box">
						<input type="file" id="upload[]" name="upload[]" />
					</div>
				</div>
				<div class="clear"></div>
				<div id="add2" class="left filelist"></div>
				<div class="left clear">
					<div class="left add_sub_file_btn">
						<span onclick="add()" href="#"><?php echo $html->image('list-add.png')?></span>&nbsp;
						<span onclick="remove()" href="#"><?php echo $html->image('list-remove.png')?></span>
					</div>
				</div>
			 </div>
			</div>
		</div>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
			    <div class="form_left_title left">审核状态：</div>
			      <div class="form_right_input left">
			      <?php 
			      		$comp_tid = $form->value('CompTechnology.id');
			      		if($form->value('CompTechnology.status')=="1"){?>
		           			<b><font color='green' size='3'>已审核</font></b>
	        		<?php  
			      			if( ($user['isadmin'] || $user['isgroupadmin']) && $comp_tid){
					     		echo "<input type='button' class='ec_review_btn' id='nopass' value='取消审核'/>";
							 } 
			      		}else {?>
	        				<b><font color='red' size='3' weight=bold>未审核</font></b>
	        	    <?php 
			      			if(($user['isadmin'] || $user['isgroupadmin']) && $comp_tid){
			        		 	echo "<input type='button' class='ec_review_btn' id='pass' value='通过审核'/>";
			        		 }
			      		}?>
		       </div>
			</div>	
		</div>	 
		<?php 
		echo $form->hidden('CompTechnology.owner',array('value' => $user['id'])) ;
		echo $form->hidden('CompTechnology.cid',array('value' => $companyid)) ;
		echo $form->hidden('CompTechnology.id',array('id' => "hidden_tid")) ;
	  	echo $form->hidden('CompTechnology.creater'); 	
		?>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"></div>
				<div class="form_add_submit left">
			   		 <?php echo $form->submit(__('Save',true), array("id"=>"adduser","name"=>"submit","class"=>"buttom","div"=>false));  ?>	
			   		  	    	
			    </div>
			</div>
		</div>
		</form>
	</div>
</div>
<?php echo $this->element('delfileconfirm',array("title"=>"删除提示","message"=>"你确定要删除吗？")) ?>
<script>
var webpath=$("#getpath").attr('href');
$("#CompTechnologyTypeId option:first").html('请选择类型');
function checksave(){
	if($("#CompTechnologyTname").val().trim() == ''){
		$("#technologynamemessage").css('display','block');
		return false;
	}else{
		$("#technologynamemessage").css('display','none');
	}
	if($("#CompTechnologyTypeId").val().trim() == ''){
		$("#technologytypemessage").css('display','block');
		return false;
	}else{
		$("#technologytypemessage").css('display','none');
	}
	if($("#CompTechnologyDepartment").val().trim() == ''){
		$("#departmentemessage").css('display','block');
		return false;
	}else{
		$("#departmentemessage").css('display','none');
	}
//	if($("#CompTechnologyDeclarateStatus").val().trim() == ''){
//		$("#declaratestatusmemessage").css('display','block');
//		console.log(4);
//		return false;
//	}else{
//		$("#declaratestatusmemessage").css('display','none');
//	}

	
}
$(document).ready(function() {
	$("#CompTechnologyState").change(function() {    		
			var index=this.value;
			if(index==0){
				$("#AcceptTime").css("display","none");
				$("#AuthorizeTime").css("display","none");
			}else if(index==1){
				$("#AcceptTime").css("display","");
				$("#AuthorizeTime").css("display","none");
			}else if(index==2){
				$("#AcceptTime").css("display","");
				$("#AuthorizeTime").css("display","");
			}
		});
	$("#CompTechnologyState").change();

	$(".ec_review_btn").click(function(){
		var tid = $("#hidden_tid").val();
		var state =$(this).attr("id");
		setPass(state,tid,"pro");
     });
});

function setPass(state,tid,type){
	var statevalue = 0;
	if(state == "pass"){
		statevalue = 1;
	}
	if(tid){
		location.href=webpath+'companys/setreview/'+tid+'/'+statevalue+'/'+type;
	}
}
</script>